<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="icon" href="/static/images/favicon.ico" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>业天AI网 - 最新最前沿的AI技术和资讯 - 北京业天科技有限公司</title>
    <meta name="description" content="业天AI网是一家专业从事发布人工智能、大模型、AI技术、自然语言处理、计算机视觉、机器人、机器学习、深度学习、神经网络、强化学习等领域的最新最前沿的技术和资讯的公司。">
    <meta name="keywords" content="业天AI网,AI新闻,AI资讯,前沿AI,大模型,llm,transform,人工智能信息服务,人工智能优质文章,人工智能媒体,人工智能产业服务,机器智能,机器学习,深度学习,神经网络,强化学习,计算机视觉,自然语言处理,机器人,DeepSeek,large language model,大语言模型,自然语言处理,AI聊天机器人,代码开发,创意写作,AI助手,大模型公司,人工智能">
    <!-- link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <style>
        /* 全局样式 */
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f8f9fa;
        }
        
        /* 导航栏样式 */
        .navbar {
            background-color: #ffffff;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }
        
        /* 热门新闻样式 */
        .hot-news {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
            margin-bottom: 30px;
        }

        /* 热门新闻竖向排列样式 */
        .hot-news .news-item {
            margin-bottom: 10px;
        }
        
        .hot-news .news-item:last-child {
            margin-bottom: 0;
        }
        
        /* 新闻列表容器样式 */
        .news-list {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        /* 新闻条目样式 - 条状显示 */
        .news-item {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            padding: 15px;
        }
        
        .news-item:hover {
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
        }

        /* 新闻条目样式 - 条状显示 */
        .hot_news_item {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            padding: 4px;
        }

        .hot_news_item:hover {
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
        }
        
        .news-img {
            width: 120px;
            height: 80px;
            object-fit: cover;
            border-radius: 5px;
            margin-right: 15px;
            flex-shrink: 0;
        }

        .hot_news_img {
            width: 80px;
            object-fit: cover;
            border-radius: 5px;
            margin-right: 5px;
            flex-shrink: 0;
        }
        
        .news-content {
            flex: 1;
            min-width: 0;
        }
        
        .news-title {
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 8px;
            color: #333;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .news-date {
            font-size: 12px;
            color: #999;
        }
        
        /* 响应式调整 */
        @media (max-width: 576px) {
            .col-md-4 {
                display: none;
            }
            
            .news-item {
                padding: 4px;
            }
            
            .news-img {
                width: 100px;
                height: 70px;
                margin-right: 10px;
            }
            
            .news-title {
                font-size: 18px;
            }
        }
        
        /* 加载更多按钮样式 */
        .load-more {
            text-align: center;
            margin: 30px 0;
        }
        
        .load-more-btn {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 30px;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        
        .load-more-btn:hover {
            background-color: #0056b3;
        }
        
        /* 加载中动画 */
        .loading {
            display: none;
            text-align: center;
            padding: 20px;
        }
        
        .loading::after {
            content: '';
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #007bff;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            display: inline-block;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        /* 响应式调整 */
        @media (max-width: 768px) {
            .col-md-4 {
                display: none;
            }
            .masonry-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light">
        <div class="container">
            <a class="navbar-brand" href="/index">
                <img src="/static/images/logo.jpg" alt="业天AI网" height="30">
                <span class="ml-2 font-weight-bold">业天AI网 - 北京业天科技有限公司</span>
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse justify-content-end" id="navbarNav">
                <!-- 搜索功能模块 -->
                <form class="form-inline my-2 my-lg-0" id="searchForm" style="display: flex; align-items: center; white-space: nowrap;">
                    <input class="form-control mr-sm-2" type="search" placeholder="搜索新闻" aria-label="Search" name="keyword" id="searchKeyword" style="flex-shrink: 1;">
                    <button class="btn btn-outline-success my-2 my-sm-0" type="button" onclick="validateSearch()" style="flex-shrink: 0;">搜索</button>
                </form>
                
                <ul class="navbar-nav">
                    <li class="nav-item active">
                        <a class="nav-link" href="/index">首页 <!-- span class="sr-only">(current)</span --></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/login">登录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/register">注册</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- JavaScript -->
    <!--
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.min.js"></script>
    -->
    <script src="/static/js/jquery-3.5.1.slim.min.js"></script>
    <script src="/static/js/popper.min.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    
    <!-- 空搜索验证模态框 -->
      <div class="modal fade" id="emptySearchModal" tabindex="-1" role="dialog" aria-labelledby="emptySearchModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="emptySearchModalLabel">提示</h5>
                <button type="button" class="close" id="closeModalBtn" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                请输入关键字
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirmModalBtn">确定</button>
              </div>
          </div>
        </div>
      </div>

      <script>
        function validateSearch() {
          const keywordInput = document.getElementById('searchKeyword');
          const keyword = keywordInput.value.trim();
          
          if (keyword === '') {
            // 显示提示模态框
            $('#emptySearchModal').modal('show');
          } else {
            // 表单提交到搜索结果页面
            const searchForm = document.getElementById('searchForm');
            searchForm.action = '/news/search';
            searchForm.method = 'GET';
            searchForm.submit();
          }
        }
        
        function focusSearchInput() {
          // 当模态框关闭后，将焦点定位到搜索输入框
          setTimeout(() => {
            document.getElementById('searchKeyword').focus();
          }, 300);
        }
        
        // 为关闭按钮绑定事件
        document.getElementById('closeModalBtn').addEventListener('click', function() {
          $('#emptySearchModal').modal('hide');
          focusSearchInput();
        });
        
        // 为确认按钮绑定事件
        document.getElementById('confirmModalBtn').addEventListener('click', function() {
          $('#emptySearchModal').modal('hide');
          focusSearchInput();
        });
        
        // 监听模态框的隐藏事件，确保焦点正确设置
        $('#emptySearchModal').on('hidden.bs.modal', function () {
          focusSearchInput();
        });
        
        // 监听背景点击关闭事件
        $('#emptySearchModal').on('click', function (e) {
          if (e.target === this) {
            $(this).modal('hide');
            focusSearchInput();
          }
        });
      </script>

      <!-- 主要内容 -->
    <div class="container mt-5">
        <div class="row">
            <!-- 主内容区域 -->
            <div class="col-md-8">
                <!-- 新闻列表区域 - 条状显示 -->
                <h2 class="text-center mb-4">📰 最新新闻</h2>
                <div id="news-container" class="news-list">
                    <!-- 新闻条目将通过JavaScript动态加载 -->
                </div>
            </div>

            <!-- 右边栏 - 350px宽 -->
            <div class="col-md-4" style="max-width: 350px;">
                <!-- 热门新闻区域 - 竖向排列 -->
                <div class="hot-news">
                    <h2 class="text-center mb-4">🔥 热门新闻</h2>
                    {% if hot_news %}
                        {% for news in hot_news %}
                            <div class="hot_news_item mb-3">
                                <a href="/news/{{ news[0] }}" style="text-decoration: none; color: inherit;" target="_blank">
                                <img class="hot_news_img" src="{{ news[2] if news[2] else '/static/images/default.jpg' }}" alt="{{ news[1] }}">
                                </a>
                                <div class="news-content">
                                    <h3 class="news-title"><a href="/news/{{ news[0] }}" style="text-decoration: none; color: inherit;font-size: 16px;" target="_blank">{{ news[1] }}</a></h3>
                                </div>
                            </div>
                        {% endfor %}
                    {% else %}
                        <p class="text-center">暂无热门新闻</p>
                    {% endif %}
                </div>
            </div>
        </div>

        <!-- 加载更多按钮 -->
        <div class="load-more">
            <div id="loading" class="loading"></div>
            <button id="load-more-btn" class="load-more-btn">加载更多</button>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h4>关于我们</h4>
                    <p>业天AI网，提供最新、最全面的、前沿AI新闻资讯。</p>
                </div>
                <div class="col-md-6">
                    <h4>网站备案</h4>
                    <p>ICP备案号：京ICP备18022528号-5</p>
                    <p><a href="https://beian.miit.gov.cn/" target="_blank">备案查询</a></p>
                </div>
            </div>
            <div class="text-center mt-4">
                <p>&copy; 2025 业天AI网. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <!-- JavaScript -->
    <!-- script src="https://code.jquery.com/jquery-3.6.0.min.js"></script -->
    <!-- script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script -->
    <script src="/static/js/jquery-3.6.0.min.js"></script>
    <script src="/static/js/bootstrap.bundle.min.js"></script>
    <script>
        // 初始化页面变量
        let currentPage = 1;
        let isLoading = false;
        let hasNoMoreData = false; // 标志是否已无更多数据

        // 页面加载完成后，加载第一页新闻
        $(document).ready(function() {
            loadNews();
            
            // 加载更多按钮点击事件
            $('#load-more-btn').click(function() {
                if (!isLoading && !hasNoMoreData) {
                    loadNews();
                }
            });

            // 滚动到底部自动加载更多
            $(window).scroll(function() {
                if ($(window).scrollTop() + $(window).height() >= $(document).height() - 200) {
                    if (!isLoading && !hasNoMoreData) {
                        loadNews();
                    }
                }
            });
        });

        // 加载新闻函数
        function loadNews() {
            isLoading = true;
            $('#loading').show();
            $('#load-more-btn').hide();

            // 发送AJAX请求获取新闻数据
            $.ajax({
                url: '/api/news',
                type: 'GET',
                data: { page: currentPage },
                dataType: 'json',
                success: function(response) {
                    if (response.news && response.news.length > 0) {
                        // 将新闻数据渲染到页面上
                        renderNews(response.news);
                        
                        // 更新当前页码
                        currentPage++;
                        
                        // 如果还有更多数据，显示加载更多按钮
                        if (response.has_more) {
                            $('#load-more-btn').show();
                        } else {
                            // 如果没有更多数据，隐藏加载更多按钮
                            $('#load-more-btn').hide();
                        }
                    } else {
                        // 如果没有新闻数据，隐藏加载更多按钮并设置标志
                        $('#load-more-btn').hide();
                        hasNoMoreData = true;
                    }
                },
                error: function() {
                    console.error('加载新闻失败');
                },
                complete: function() {
                    isLoading = false;
                    $('#loading').hide();
                }
            });
        }

        // 渲染新闻函数
        function renderNews(newsList) {
            const container = $('#news-container');
            
            newsList.forEach(function(news) {
                // 创建新闻条目 - 条状显示
                const item = $(`
                    <div class="news-item">
                        <a href="/news/${news.id}" style="text-decoration: none; color: inherit;" target="_blank">
                            <img class="news-img" src="${news.face_img || '/static/images/default.jpg'}" alt="${news.title}">
                        </a>
                        <div class="news-content">
                            <h3 class="news-title"><a href="/news/${news.id}" style="text-decoration: none; color: inherit;" target="_blank">${news.title}</a></h3>
                            <p class="news-date">${news.publish_at}</p>
                        </div>
                    </div>
                `);
                
                // 将新闻条目添加到容器中
                container.append(item);
            });
        }
    </script>
</body>
</html>